package com.erp.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.erp.dto.Forum;
import com.erp.dto.Page;

@SuppressWarnings("serial")
@Controller(value = "forumAction")
@Scope(value = "prototype")
public class ForumAction extends ModelDrivenBaseAction<Forum> {

	/**
	 * 添加页面
	 */
	public String addPage() throws Exception {
		return "addPage";
	}

	/**
	 * 添加操作
	 */
	public void add() throws Exception {
		forumService.add(model);
		writeJson("msg", "true");
	}

	/**
	 * 删除操作
	 */
	public void delete() throws Exception {
		forumService.setStatusDeleted(model);
		writeJson("msg", "true");
	}

	/**
	 * 恢复版块
	 */
	public void undelete() throws Exception {
		forumService.setStatusNormal(model);
		writeJson("msg", "true");
	}

	/**
	 * 彻底删除版块
	 */
	public void completelyDelete() throws Exception {
		forumService.delete(model);
		writeJson("msg", "true");
	}

	/**
	 * 编辑页面
	 */
	public String editPage() throws Exception {
		model = forumService.getForumById(model.getId());
		pushIntoValueStack(model);
		return "editPage";
	}

	/**
	 * 编辑操作
	 */
	public void edit() throws Exception {
		forumService.update(model);
		writeJson("msg", "true");
	}

	/**
	 * 上移
	 */
	public void moveUp() throws Exception {
		forumService.moveUp(model);
		writeJson("msg", "true");
	}

	/**
	 * 下移
	 */
	public void moveDown() throws Exception {
		forumService.moveDown(model);
		writeJson("msg", "true");
	}

	/**
	 * 显示板块列表
	 */
	public String list() throws Exception {
		if (page == null) {
			page = new Page();
		}
		return pagedList();
	}

	/**
	 * 所有用户列表
	 */
	public String listAll() throws Exception {
		request.put("forumList", forumService.listAll());
		return "list";
	}

	/**
	 * 分页后的用户列表
	 */
	public String pagedList() throws Exception {
		request.put("forumList", forumService.getPagedList(page));
		pushIntoValueStack(page);
		return "list";
	}

	public String query() throws Exception {

		return "";
	}

	/**
	 * 获取版块回收站列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String recycleList() throws Exception {
		request.put("forumRecycleList", forumService.getRecycleList());
		return "recycleList";
	}
}
